{extend name="sitehome@style/base"/}

{block name="resources"}
{/block}

{block name="main"}
<div class="nc-table-box">
    <table id="pay_list" lay-filter="pay_list" class="layui-table"></table>
</div>
<script type="text/html" id="title">
	<p class="img-wrap">
		<img src="ADDON_NS_OAUTH_LOGIN_IMG/{{d.info.name}}.png" onerror="imgError(this)"/>
	</p>
	<span class="table-title">{{d.info.title}}</span>
</script>
<script type="text/html" id="status">
	<input class="select-input" type="checkbox" name="status" value="{{d.config.name}}" lay-skin="switch" lay-filter="status" {{ d.config.status==1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="operation">
	<a class="default" href="{{ nc.url(d.info.url) }}">编辑</a>
</script>
{/block}

{block name="script"}
<script>
var table = new Table({
	elem: '#pay_list',
	filter : "pay_list",
	url: '{:addon_url("OAuthLogin://sitehome/Loginconfig/lists")}',
	cols: [
		[
			{
				field: 'title',
				width: '40%',
				title: '登录方式',
				templet: '#title',
                unresize : 'true'
			},
			{
				field: 'site_config_status',
				width: '40%',
				title: '状态',
				templet: '#status',
                unresize : 'true'
			},
			{
				title: '操作',
                align: 'right',
				toolbar: '#operation',
                unresize : 'true'
			}
		]
	]
});

//监听工具条
table.tool(function(obj) {
	var data = obj.data;
	var event = obj.event;
	switch (event) {
		case 'edit':
			location.href = nc.url('OAuthLogin://sitehome/loginconfig/config', {addon_name: data.name});
			break;
	}
});

layui.use('form', function() {
	var form = layui.form;
	//开关监听
	form.on('switch(status)', function(data) {
		var name = data.value;
		var status = data.elem.checked ? 1 : 0;
		$.ajax({
			type : "post",
			url : '{:addon_url("OAuthLogin://sitehome/loginconfig/setOAuthLoginStatus")}',
			data : {
				'status' : status,
				'name' : name
			},
			dataType : "JSON",
			success : function(res) {
				layer.msg(res.message);
			}
		});
		return false;
	});
});

function imgError(element) {
	element.src = '';
}
</script>
{/block}